home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / Musique / Quod Libet / quodlibet-3.3.0-installer.exe / bin / quodlibet / qltk / sliderbutton.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2014-12-31  |  9KB  |  208 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.7)
  3.  
  4. from gi.repository import Gtk, Gdk
  5. from quodlibet.qltk import get_top_parent
  6. from quodlibet.qltk.x import Alignment
  7.  
  8. class PrimaryWarpsRange(Gtk.Range):
  9.     '''A GtkRange which behaves as if gtk-primary-button-warps-slider
  10.     was always True.
  11.  
  12.     Adjusts key events depending on the current settings value.
  13.     '''
  14.     
  15.     def __init__(self, *args, **kwargs):
  16.         super(PrimaryWarpsRange, self).__init__(*args, **kwargs)
  17.         self.connect('button-press-event', self._PrimaryWarpsRange__button_event)
  18.         self.connect('button-release-event', self._PrimaryWarpsRange__button_event)
  19.  
  20.     
  21.     def _warps(self):
  22.         settings = Gtk.Settings.get_default()
  23.         if settings:
  24.             
  25.             try:
  26.                 return settings.get_property('gtk-primary-button-warps-slider')
  27.             except TypeError:
  28.                 pass
  29.             
  30.  
  31.         return False
  32.  
  33.     _warps = property(_warps)
  34.     
  35.     def __button_event(self, widget, event):
  36.         if not self._warps:
  37.             event.button = event.button % 3 + 1
  38.         return False
  39.  
  40.  
  41.  
  42. class PrimaryWarpsScale(Gtk.Scale, PrimaryWarpsRange):
  43.     pass
  44.  
  45.  
  46. class _PopupSlider(Gtk.Button):
  47.     
  48.     def __init__(self, child = None, adj = None):
  49.         super(_PopupSlider, self).__init__()
  50.         if child:
  51.             self.add(child)
  52.         self.connect('clicked', self._PopupSlider__clicked)
  53.         window = self._PopupSlider__window = Gtk.Window(type = Gtk.WindowType.POPUP)
  54.         if not adj:
  55.             pass
  56.         self._PopupSlider__adj = self._adj
  57.         frame = Gtk.Frame()
  58.         frame.set_border_width(0)
  59.         frame.set_shadow_type(Gtk.ShadowType.OUT)
  60.         self.add_events(Gdk.EventMask.SCROLL_MASK)
  61.         hscale = PrimaryWarpsScale(adjustment = self._PopupSlider__adj)
  62.         hscale.set_orientation(self.ORIENTATION)
  63.         window.connect('button-press-event', self._PopupSlider__button)
  64.         window.connect('key-press-event', self._PopupSlider__key)
  65.         hscale.set_draw_value(False)
  66.         self.scale = hscale
  67.         window.add(frame)
  68.         self._box = Gtk.Box(orientation = self.ORIENTATION)
  69.         self._box.add(hscale)
  70.         frame.add(self._box)
  71.         self.connect('scroll-event', self._PopupSlider__scroll, hscale)
  72.         self.connect('destroy', self._PopupSlider__destroy)
  73.         
  74.         def foward_scroll(scale, event):
  75.             self.emit('scroll-event', event.copy())
  76.  
  77.         window.connect('scroll-event', foward_scroll)
  78.         self.scale.connect('scroll-event', (lambda : True))
  79.         
  80.         def handle_all(scale, event):
  81.             return True
  82.  
  83.         self.scale.connect_after('button-press-event', handle_all)
  84.         self.scale.connect_after('button-release-event', handle_all)
  85.         self.set_slider_length(200)
  86.         if child:
  87.             self.get_child().show_all()
  88.  
  89.     
  90.     def _PopupSlider__destroy(self, *args):
  91.         self._PopupSlider__window.destroy()
  92.         self._PopupSlider__window = None
  93.  
  94.     
  95.     def set_slider_length(self, length):
  96.         if self.ORIENTATION == Gtk.Orientation.HORIZONTAL:
  97.             self.scale.set_size_request(length, -1)
  98.         else:
  99.             self.scale.set_size_request(-1, length)
  100.         self._PopupSlider__window.resize(1, 1)
  101.  
  102.     
  103.     def set_slider_widget(self, widget):
  104.         self._box.pack_start(Alignment(widget, left = 3, right = 3), False, True, 0)
  105.  
  106.     
  107.     def _move_to(self, x, y, w, h, ww, wh, pad = 3):
  108.         raise NotImplementedError
  109.  
  110.     
  111.     def _PopupSlider__clicked(self, button):
  112.         if self._PopupSlider__window.get_property('visible'):
  113.             return None
  114.         window = None._PopupSlider__window
  115.         frame = window.get_child()
  116.         frame.show_all()
  117.         window.size_request()
  118.         (dummy, x, y) = self.get_window().get_origin()
  119.         (x, y) = self.translate_coordinates(self.get_toplevel(), x, y)[:2]
  120.         button_alloc = self.get_allocation()
  121.         w = button_alloc.width
  122.         h = button_alloc.height
  123.         (ww, wh) = window.get_size()
  124.         (sx, sy) = self._move_to(x, y, w, h, ww, wh, pad = 3)
  125.         window.set_transient_for(get_top_parent(self))
  126.         window.move(sx, sy)
  127.         window.show()
  128.         window.grab_focus()
  129.         window.grab_add()
  130.         event_time = Gtk.get_current_event_time()
  131.         pointer = Gdk.pointer_grab(window.get_window(), True, Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.BUTTON_RELEASE_MASK | Gdk.EventMask.BUTTON_MOTION_MASK | Gdk.EventMask.POINTER_MOTION_MASK | Gdk.EventMask.SCROLL_MASK, None, None, event_time)
  132.         keyboard = Gdk.keyboard_grab(window.get_window(), True, event_time)
  133.         grab_sucess = Gdk.GrabStatus.SUCCESS
  134.         if pointer != grab_sucess or keyboard != grab_sucess:
  135.             window.grab_remove()
  136.             window.hide()
  137.             if pointer == Gdk.GrabStatus.SUCCESS:
  138.                 Gdk.pointer_ungrab(event_time)
  139.             if keyboard == Gdk.GrabStatus.SUCCESS:
  140.                 Gdk.keyboard_ungrab(event_time)
  141.             
  142.  
  143.     
  144.     def _PopupSlider__scroll(self, widget, ev, hscale):
  145.         adj = self._PopupSlider__adj
  146.         v = hscale.get_value()
  147.         if ev.direction in self.UP:
  148.             v += adj.props.step_increment
  149.         elif ev.direction in self.DOWN:
  150.             v -= adj.props.step_increment
  151.         else:
  152.             return None
  153.         v = None(adj.props.upper, max(adj.props.lower, v))
  154.         hscale.set_value(v)
  155.  
  156.     
  157.     def _PopupSlider__button(self, widget, ev):
  158.         self._PopupSlider__popup_hide()
  159.  
  160.     
  161.     def _PopupSlider__key(self, hscale, ev):
  162.         if ev.string in ('\n', '\r', ' ', '\x1b'):
  163.             self._PopupSlider__popup_hide()
  164.  
  165.     
  166.     def _PopupSlider__popup_hide(self):
  167.         window = self._PopupSlider__window
  168.         event_time = Gtk.get_current_event_time()
  169.         window.grab_remove()
  170.         Gdk.pointer_ungrab(event_time)
  171.         Gdk.keyboard_ungrab(event_time)
  172.         window.hide()
  173.         window.unrealize()
  174.  
  175.  
  176.  
  177. class HSlider(_PopupSlider):
  178.     ORIENTATION = Gtk.Orientation.HORIZONTAL
  179.     _adj = Gtk.Adjustment.new(0, 0, 0, 3, 15, 0)
  180.     UP = [
  181.         Gdk.ScrollDirection.DOWN,
  182.         Gdk.ScrollDirection.RIGHT]
  183.     DOWN = [
  184.         Gdk.ScrollDirection.UP,
  185.         Gdk.ScrollDirection.LEFT]
  186.     
  187.     def _move_to(self, x, y, w, h, ww, wh, pad = 3):
  188.         if Gtk.Widget.get_default_direction() == Gtk.TextDirection.LTR:
  189.             return (x + w + pad, y + (h - wh) // 2)
  190.         return (None - ww + pad, y + (h - wh) // 2)
  191.  
  192.  
  193.  
  194. class VSlider(_PopupSlider):
  195.     ORIENTATION = Gtk.Orientation.VERTICAL
  196.     _adj = Gtk.Adjustment.new(0, 0, 1, 0.05, 0.1, 0)
  197.     UP = [
  198.         Gdk.ScrollDirection.UP,
  199.         Gdk.ScrollDirection.LEFT]
  200.     DOWN = [
  201.         Gdk.ScrollDirection.DOWN,
  202.         Gdk.ScrollDirection.RIGHT]
  203.     
  204.     def _move_to(self, x, y, w, h, ww, wh, pad = 3):
  205.         return (x + (w - ww) // 2, y + h + pad)
  206.  
  207.  
  208.